# encoding: utf-8
$:.unshift File.join(File.dirname(__FILE__))

require 'table'
require 'csv'

tbl = Table.new
puts tbl.longtable(
    label: "Tab001",
    caption: "This text will appear above the table",
    caption_toc: "This text will appear in the table of contents",
    col_def: ['c', 'c', 'c'],
    header: ['Column 1', 'A & B', 'Column 3'],
    data: [[1,2,3], [4,'A & B',5], [6,7,8]]
)


puts "\nLatex-Tabelle aus Datei:"
a = CSV.read("A:/Test.csv", col_sep: ';', headers: false)

puts tbl.longtable(
    label: "Tab001",
    caption: "This text will appear above the table",
    caption_toc: "This text will appear in the table of contents",
    col_def: ['c', 'c', 'c', 'c', 'c', 'c'],
    header: a.to_a.delete_at(0),
    data: a.to_a
)

# Print errors if available
if tbl.errors.count > 0
  tbl.errors.each do |item|
    puts item
    puts "-" * 80
  end
end
